package UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;

public class UDPSender {
    public static void main(String[] args) {
        try {
            for(int i = 1 ; i <= 10 ; i++) {
                //创建socket
                DatagramSocket socket = new DatagramSocket();
                //创建packet
                byte[] data = "hello".getBytes();
                DatagramPacket packet = new DatagramPacket(data, data.length, new InetSocketAddress("localhost", 6666));
                //发送
                socket.send(packet);
                socket.close();
                Thread.sleep(10000);
            }
        } catch (Exception e){
            e.printStackTrace();
        }

    }
}
